import 'package:data/repository/home_articles/home_articles_repository.dart';
import 'package:domain/mapper/article_domain_model_mapper.dart';
import 'package:domain/model/article_domain_model.dart';

abstract class HomeArticleUseCase {
  Future<List<ArticleDomainModel>> fetchArticles({int page = 1});
}

class HomeArticleUseCaseImpl implements HomeArticleUseCase {
  final HomeArticlesRepository _repository;

  const HomeArticleUseCaseImpl({required HomeArticlesRepository repository})
    : _repository = repository;

  @override
  Future<List<ArticleDomainModel>> fetchArticles({int page = 1}) async {
    final resultList = await _repository.fetchHomeArticles(page: page);
    return resultList.map((item) => item.toDomainModel()).toList();
  }
}
